let rec power x n =
  match n with
    | 0 -> 1
    |_ -> x * power x (n-1)
;;
power 5 2;;

let rec application polynome x =
  match polynome with
    |[] ->0
    |(a,b)::poly -> a * power x b + application poly x
;;  


let rec add polynome1 polynome2 =
  match (polynome1,polynome2)with
    |([],[])-> []
    |(poly1,[])-> poly1
    |([],poly2)-> poly2
    |( (a,b)::poly1 ),( (c,d)::poly2 ) -> 
      begin 
	if b=d then 
	  begin
	  (a + c, b)::add poly1 poly2
	  end
	else if b>d then 
	  begin
	  (c , d)::add ((a , b)::poly1) poly2
	  end
	else 
	  begin
	  (a , b)::add poly1 ((c,d)::poly2)
	  end 
      end
;;




let rec soustract polynome1 polynome2 =
  match (polynome1,polynome2)with
    |([],[])-> []
    |(poly1,[])-> poly1
    |([],poly2)-> poly2
    |( (a,b)::poly1 ),( (c,d)::poly2 ) -> 
      begin 
	if b=d then 
	  begin
	    begin
	      if a=c then
		soustract poly1 poly2
	      else 
		(a - c, b)::soustract poly1 poly2
	    end
	  end
	else if b>d then 
	  begin
	  (c , d)::soustract ((a , b)::poly1) poly2
	  end
	else 
	  begin
	  (a , b)::soustract poly1 ((c,d)::poly2)
	  end 
      end
;;




let rec deriv polynome =
  match polynome with
    |[]->[]
    |(a,b)::poly -> (a*b,b-1)::deriv poly
;;

power 5 2;;
application [(2,2);(2,3);(4,4)] 2;;
add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;
soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;
deriv [(2,2);(2,3);(4,4)];;




